static char SccsId[] = "@(#)aslquad.c	1.4   10/6/95";
/*
 *         Copyright (c) KUBOTA Corporation and HUDSON SOFT,
 *                  1994, 1995 All Rights Reserved
 *
 *  This software comprises unpublished confidential information of
 *  KUBOTA Corp. and HUDSON SOFT. It may not be used, copied or made
 *  available to anyone, except in accordance with the license under
 *  which it is furnished.
 */

#define	_ASLLIB_
#define	_ASLQUAD_C_

#include <farl.h>
#include <asl.h>

#if !defined( max )
#define max(x,y)	(((x)>(y))?(x):(y))
#endif
#if !defined( min )
#define min(x,y)	(((x)<(y))?(x):(y))
#endif

/*----------------------------------------------------------------------------*/
void
ASLMakeQuadrangleSprite( ASLSource *src,	ASLQuadrangleParameter	*param,
	ASLPt		pt[],			ASLSct *sct )
{
	int	dstX, dstW, i;
	int	leftInc, rightInc, xl, xr, w, xstep, ystep;

	dstX = min( param->dstXt, param->dstXb );
	dstW = max( ( param->dstXt + param->dstWt ),
			( param->dstXb + param->dstWb ) ) - dstX;
	leftInc	 = ( ( (int)param->dstXb - (int)param->dstXt ) * 256 )
							/ (int)param->dstH;
	rightInc = ( ( ( (int)param->dstXb + (int)param->dstWb )
			- ( (int)param->dstXt + (int)param->dstWt ) ) * 256 )
							/ (int)param->dstH;
	ystep = ( (int)( src->x_size ) * 256 ) / (int)param->dstH;

	for ( i = 0, xl = (int)param->dstXt * 256,
			xr = (int)( param->dstXt + param->dstWt ) * 256;
			i < param->dstH; i++, xl += leftInc, xr += rightInc ) {
		xstep = ( (int)( src->x_size ) * 65536 ) / ( xr - xl );
		pt[i].x_off  = -( xstep * ( xl - dstX * 256 ) ) / 65536;
		pt[i].y_off  = ( ystep * i ) / 256;
		pt[i].x_scan = xstep;
		pt[i].y_scan = 0;
	}

	sct->head	 = ASL_VAL_FNC_TBL | ( src->bank & ASL_MSK_BANKSEL );
	sct->cntl	 = 0;
	sct->dsp_x_pos	 = dstX & ASL_MSK_DSP_X_POS;
	sct->dsp_y_pos	 = param->dstY & ASL_MSK_DSP_Y_POS;
	sct->dsp_xy_size = ( ( ( dstW - 1 ) << ASL_SFT_DSP_X_SIZE )
							& ASL_MSK_DSP_X_SIZE )
			 | ( ( ( param->dstH - 1 ) << ASL_SFT_DSP_Y_SIZE )
							& ASL_MSK_DSP_Y_SIZE );
	sct->src_xy_pos	 =
		  ( (  src->x_pos << ASL_SFT_SRC_X_POS ) & ASL_MSK_SRC_X_POS )
		| ( (  src->y_pos << ASL_SFT_SRC_Y_POS ) & ASL_MSK_SRC_Y_POS );
	sct->src_xy_size = ( ( ( src->x_size - 1 ) << ASL_SFT_SRC_X_SIZE )
							& ASL_MSK_SRC_X_SIZE )
			 | ( ( ( src->y_size - 1 ) << ASL_SFT_SRC_Y_SIZE )
							& ASL_MSK_SRC_Y_SIZE );
	sct->pt_bank_sel = param->ptBank & ASL_MSK_PT_BANKSEL;
	sct->pt_off_addr = param->ptOffAddr;
}

/*----------------------------------------------------------------------------*/
